import java.io.*;
import java.util.*;

import jxl.*;
import jxl.read.biff.BiffException;


public class modelling {
	 
	String message ="" ;
	public String findWinner(String first, String second, Double odds) throws IOException {
        Double bet = odds;
		Workbook w;
		File inputWorkbook = new File("results.xls");
		String qn="Montreal";
		String a = new String ("W");
		String vgf = new String ("L");
		String d = new String ("W");
		int wq1 = 0,i,j,l,m,vvf = 0, qw,count1 = 0,count2 = 0, pos = 0;

		try { 
	
		w = Workbook.getWorkbook(inputWorkbook);
		Sheet sheet = w.getSheet(0);
		
/* ---------------------------------------------------------------------------------------------------------------*/		
		
		if(first.equals("anaheim") && second.equals("chicago")) {
			
		// ANAHEIM
		for (j=1; j < 2; j++) {
			
			for (i=0; i<sheet.getRows(); i++) {
				Cell cell  = sheet.getCell (j,i);
				String b = new String(cell.getContents()); 
				if (a.equals(b)) { count1 ++;}	
				}	
		}
		//CHICAGO
	for (m=10; m < 11; m++) {
			
			for (l=0; l<sheet.getRows(); l++) {
				Cell cell  = sheet.getCell (m,l);
				String c = new String(cell.getContents()); 
				if (d.equals(c)) { count2 ++;}	
					}	
		}
	if (count1 > count2) {
		message = "Winner will be Anaheim!" ;
	}
	else {
		message = "Winner will be Chicago Blackhawks!";
	}	
		} 
	else if (second.equals("anaheim") && first.equals("chicago")) {
			// ANAHEIM
			for (j=1; j < 3; j++) {
				
				for (i=0; i<sheet.getRows(); i++) {
					Cell cell  = sheet.getCell (j,i);
					String b = new String(cell.getContents()); 
					if (a.equals(b)) { count1 ++;}	
					
				}	
			}
			//CHICAGO
		for (m=10; m < 11; m++) {
				
				for (l=0; l<sheet.getRows(); l++) {
					Cell cell  = sheet.getCell (m,l);
					String c = new String(cell.getContents()); 
					if (d.equals(c)) { count2 ++;}	
						}	
			}
		if (count1 > count2) {
			message = "Winner will be Anaheim!" ;
		}
		else {
			message = "Winner will be Chicago Blackhawks!";
		}	}
		
		
		
/*--------------------------------------------------------------------------------------------------------------*/		
	else if(first.equals("vancouver") && second.equals("montreal")) {
		
		// VANCOUVER
		for (j=19; j < 21; j++) {
			
			for (i=3; i<sheet.getRows(); i++) {
				Cell cell  = sheet.getCell (j,i);
				String b = new String(cell.getContents()); 
				if (a.equals(b)) { count1 ++;}
				else if (qn.equals(b)){Cell cell1 = sheet.getCell(j+1,i);
				String bb = new String(cell1.getContents());
				if (vgf.equals(bb)){vvf = vvf - 5;}
				else if(a.equals(bb)){ vvf = vvf + 5;}
				else{}
				}
			}	
		}

		//MONTREAL
	for (m=29; m < 30; m++) {
			
			for (l=3; l<sheet.getRows(); l++) {
				Cell cell  = sheet.getCell (m,l);
				String c = new String(cell.getContents()); 
				if (d.equals(c)) { count2 ++;}	
					}	
		}
		if (bet < 2.0 && bet >= 1.95) { pos = 10;} else if (bet < 1.95 && bet >= 1.90) { pos = 20;} else if (bet < 1.90 && bet >= 1.85) { pos = 30;} else if (bet < 1.85 && bet >= 1.80) { pos = 40;} else if (bet < 1.80 && bet >= 1.75) { pos = 50;} else if (bet < 1.75 && bet >= 1.70) { pos = 60;} else if (bet < 1.70 && bet >= 1.65) { pos = 70;}else if (bet < 1.65 && bet >= 1.60) { pos = 80;} else{}
		 qw = count1-count2 ;
		wq1 = (10*qw) - 20 + vvf + pos ;
		
	if ( wq1 > 0 ){
	    message = "vancouver wins!";
		System.out.println(wq1); }
		
	else {message = "Winner will be Montreal!";	
	System.out.println(wq1+"  "+ pos);}
	}
	else if(second.equals("vancouver") && first.equals("montreal")) {
			// VANCOUVER
			for (j=19; j < 20; j++) {
				
				for (i=0; i<sheet.getRows(); i++) {
					Cell cell  = sheet.getCell (j,i);
					String b = new String(cell.getContents()); 
					if (a.equals(b)) { count1 ++;}	
					}	
			}
			//MONTREAL
		for (m=28; m < 29; m++) {
				
				for (l=0; l<sheet.getRows(); l++) {
					Cell cell  = sheet.getCell (m,l);
					String c = new String(cell.getContents()); 
					if (d.equals(c)) { count2 ++;}	
						}	
			}
		if (count1 > count2) {
		
			message = "Winner will be Vancouver!" ;
		}
		else {
			message = "Winner will be Montreal!";
		}
		}
		else{
			message =  "Wrong entry";
		}
			w.close();
		}	
	catch (BiffException e) {
		e.printStackTrace();
	}
	return message;
		
		}
}